//
//  MianView.m
//  Homestay
//
//  Created by 邓朝中 on 2017/3/22.
//  Copyright © 2017年 ysln. All rights reserved.
//

#import "MianView.h"

@implementation MianView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addViews];
        
    }
    return self;
}

-(void)layoutSubviews{
    WS(weakself);
    
    [_background mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakself.mas_left).offset(0);
        make.top.mas_equalTo(weakself.mas_top).offset(0);
        make.width.mas_equalTo(weakself.mas_width);
        make.height.mas_equalTo(weakself.mas_height);
        
    }];
    
    [_logo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_background.mas_centerY).offset(-10);
        make.centerX.mas_equalTo(_background.mas_centerX);
        make.width.mas_equalTo(84*kDeviceHRatio);
        make.height.mas_equalTo(84*kDeviceHRatio);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(_background.mas_width);
        make.height.mas_equalTo(20*kDeviceHRatio);
        make.top.mas_equalTo(_logo.mas_bottom).offset(15*kDeviceHRatio);
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_titleLabel.mas_bottom).offset(25);
        make.centerX.mas_equalTo(_background.mas_centerX);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(40);
        
    }];
    
    [_regiserBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_loginBtn.mas_bottom).offset(20);
        make.centerX.mas_equalTo(_background.mas_centerX);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(40);
        
    }];
    
    [_goFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(_background.mas_bottom).offset(-15);
        make.centerX.mas_equalTo(_background.mas_centerX);
        make.width.mas_equalTo(_loginBtn.mas_width);
    }];
    
}

-(UIImageView *)background{
    
    if (!_background) {
        _background = [[UIImageView alloc] init];
        _background.userInteractionEnabled = YES;
        _background.image = [UIImage imageNamed:@"bg"];
        
    }
    return _background;
}

-(UIImageView *)logo{
    
    if (!_logo) {
        
        _logo = [[UIImageView alloc] init];
        _logo.image = [UIImage imageNamed:@"logo"];
    }
    return _logo;
}

-(UILabel *)titleLabel{
    
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"西藏U客";
        _titleLabel.textColor = [UIColor colorWithRed:82/255.f green:169/255.f blue:237/255.f alpha:1.0];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:16*kDeviceHRatio];
    }
    return _titleLabel;
}

-(UIButton *)loginBtn{
    
    if (!_loginBtn) {
        
        _loginBtn = [[UIButton alloc] init];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_loginBtn addTarget:self action:@selector(pushLogin:) forControlEvents:UIControlEventTouchUpInside];
        [_loginBtn setTitle:@"登 录" forState:UIControlStateNormal];
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _loginBtn.backgroundColor = [UIColor colorWithRed:82/255.f green:169/255.f blue:237/255.f alpha:1.0];
        _loginBtn.layer.cornerRadius = 10.f;
    }
    return _loginBtn;
}

-(UIButton *)regiserBtn{
    
    if (!_regiserBtn) {
        _regiserBtn = [[UIButton alloc] init];
        _regiserBtn.backgroundColor = [UIColor whiteColor];
        [_regiserBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_regiserBtn addTarget:self action:@selector(pushRegister:) forControlEvents:UIControlEventTouchUpInside];
        _regiserBtn.layer.cornerRadius = 10.f;
        _regiserBtn.layer.borderWidth = 1.f;
        _regiserBtn.layer.borderColor = [UIColor colorWithRed:82/255.f green:169/255.f blue:237/255.f alpha:1.0].CGColor;
        [_regiserBtn setTitle:@"注 册" forState:UIControlStateNormal];
        _regiserBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_regiserBtn setTitleColor:[UIColor colorWithRed:82/255.f green:169/255.f blue:237/255.f alpha:1.0] forState:UIControlStateNormal];
    }
    return _regiserBtn;
}

-(UIButton *)goFirst{
    
    if (_goFirst) {
        _goFirst = [[UIButton alloc] init];
        [_goFirst setTitle:@"让我先随便逛逛" forState:UIControlStateNormal];
        _goFirst.titleLabel.font = [UIFont systemFontOfSize:13];
        [_goFirst setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_goFirst setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_goFirst addTarget:self action:@selector(goFirst:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _goFirst;
}

- (void)addViews{
    
    [self addSubview:_background];
    
    [_background addSubview:_logo];
    
    [_background addSubview:_titleLabel];
    
    [_background addSubview:_loginBtn];
    
    [_background addSubview:_regiserBtn];
    
    [_background addSubview:_goFirst];
    
}

@end
